﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Applee.FractCommon;
using System.Drawing;

namespace Applee.CantorFract
{
    public class CantorFract : BaseFract
    {
        protected override void CreateFract(PointF point, RandomColor color, float fLength, int iterations)
        {
            if (iterations < 0)
                return;

            if (fLength < 1.0F)
                return;

            CantorRectangle cantor = new CantorRectangle();
            cantor.MakeShape(new PointF(point.X, point.Y), fLength);
            cantor.Color = color.GetColor(iterations);
            mFractObjects.Add(cantor);

            PointF[] points = cantor.Points;

            float fHeight = CantorRectangle.HEIGHT * 2;

            PointF point1 = new PointF(points[0].X, points[0].Y + fHeight);
            CreateFract(point1, color, fLength / 3.0F, iterations - 1);

            PointF point2 = new PointF(points[0].X + fLength / 3.0F * 2, points[0].Y + fHeight);
            CreateFract(point2, color, fLength / 3.0F, iterations - 1);

        }

        protected override void Initialize()
        {
            SizeF shapeSize = new SizeF(1.0F, 1.0F); //box边比1:1
            float flength = 0;
            float fMargin = 10;

            if (MathUtils.CalcAdaptiveLength(mViewSize, shapeSize, ref flength))
            {
                //width
                mLength = 1.0F * flength - fMargin * 2.0F;
            }
            else
            {
                //Height
                mLength = 1.0F * flength - fMargin * 2.0F;
            }

            mBasePoint = new PointF(mLength * 0.5F, mLength * 0.5F);

        }
    }
}
